const faker = require('faker');

faker.locale = 'zh_CN';

// 员工
const staffList = [];
for (let i = 0; i < 20; i++) {
  staffList.push({
    employeeId: faker.random.uuid(),
    name: `小明${i}`,
    sex: '男',
    age: 32,
    oneLevelDept: '超声事业部',
    oneLevelDeptName: '超声事业部',
    twoLevelDept: '生产部',
    twoLevelDeptName: '生产部',
    position: '仓管员',
    workingStatus: '在职',
    username: '谢阿三',
    roles: ['管理员', '销售'],
    lastLoginDate: (new Date()).toLocaleDateString(),
    accountStatus: '激活',
  });
}
const staffDetail = {
  name: '员工一',
  employeeId: '员工ID',
  sex: '女',
  birthday: '1900-08-22',
  mobile: '16698783454',
  age: '23',
  oneLevelDept: '一级部门',
  oneLevelDeptName: '一级部门',
  isOneLevelManager: true,
  twoLevelDept: '二级部门',
  twoLevelDeptName: '二级部门',
  isTwoLevelManager: false,
  workingStatus: '离职',
  position: '超声事业部',
  username: 'adminuser',
  password: '111111',
  passwordAgain: '111111',
  roles: ['角色1', '角色2'],
  accountStatus: '0'
};

// 角色
const roleList = [];
for (let i = 0; i < 10; i++) {
  roleList.push({
    id: faker.random.uuid(),
    roleName: `公司管理员${i}`,
    roleType: 'system'
  });
}

const makeRoleLimits = () => [{
  label: '任务',
  children: [{
    label: '审批任务',
    children: [{
      id: '1-1-1',
      label: '查看',
      value: faker.random.boolean()
    }, {
      id: '1-1-2',
      label: '编辑',
      value: faker.random.boolean()
    }, {
      id: '1-1-3',
      label: '新增',
      value: faker.random.boolean()
    }, {
      id: '1-1-4',
      label: '删除',
      value: faker.random.boolean()
    }, {
      id: '1-1-5',
      label: '导出',
      value: faker.random.boolean()
    }]
  }, {
    label: '外派任务',
    children: [{
      id: '1-2-1',
      label: '查看',
      value: faker.random.boolean()
    }, {
      id: '1-2-2',
      label: '编辑',
      value: faker.random.boolean()
    }, {
      id: '1-2-3',
      label: '新增',
      value: faker.random.boolean()
    }, {
      id: '1-2-4',
      label: '删除',
      value: faker.random.boolean()
    }, {
      id: '1-2-5',
      label: '导出',
      value: faker.random.boolean()
    }]
  }, {
    label: '突击任务',
    children: [{
      id: '1-3-1',
      label: '查看',
      value: faker.random.boolean()
    }, {
      id: '1-3-2',
      label: '编辑',
      value: faker.random.boolean()
    }, {
      id: '1-3-3',
      label: '新增',
      value: faker.random.boolean()
    }, {
      id: '1-3-4',
      label: '删除',
      value: faker.random.boolean()
    }, {
      id: '1-3-5',
      label: '导出',
      value: faker.random.boolean()
    }]
  }]
}, {
  label: '采购',
  children: [{
    label: '采购申请',
    children: [{
      id: '2-1-1',
      label: '查看',
      value: faker.random.boolean()
    }, {
      id: '2-1-2',
      label: '编辑',
      value: faker.random.boolean()
    }, {
      id: '2-1-3',
      label: '新增',
      value: faker.random.boolean()
    }, {
      id: '2-1-4',
      label: '删除',
      value: faker.random.boolean()
    }, {
      id: '2-1-5',
      label: '导出',
      value: faker.random.boolean()
    }]
  }, {
    label: '采购订单',
    children: [{
      id: '2-2-1',
      label: '查看',
      value: faker.random.boolean()
    }, {
      id: '2-2-2',
      label: '编辑',
      value: faker.random.boolean()
    }, {
      id: '2-2-3',
      label: '新增',
      value: faker.random.boolean()
    }, {
      id: '2-2-4',
      label: '删除',
      value: faker.random.boolean()
    }, {
      id: '2-2-5',
      label: '导出',
      value: faker.random.boolean()
    }]
  }]
}, {
  label: '库存',
  children: [{
    label: '入库',
    children: [{
      id: '3-1-1',
      label: '查看',
      value: faker.random.boolean()
    }, {
      id: '3-1-2',
      label: '编辑',
      value: faker.random.boolean()
    }, {
      id: '3-1-3',
      label: '新增',
      value: faker.random.boolean()
    }, {
      id: '3-1-4',
      label: '删除',
      value: faker.random.boolean()
    }, {
      id: '3-1-5',
      label: '导出',
      value: faker.random.boolean()
    }]
  }, {
    label: '盘点',
    children: [{
      id: '3-2-1',
      label: '查看',
      value: faker.random.boolean()
    }, {
      id: '3-2-2',
      label: '编辑',
      value: faker.random.boolean()
    }, {
      id: '3-2-3',
      label: '新增',
      value: faker.random.boolean()
    }, {
      id: '3-2-4',
      label: '删除',
      value: faker.random.boolean()
    }, {
      id: '3-2-5',
      label: '导出',
      value: faker.random.boolean()
    }]
  }]
}];

// 审批
const approveList = [];
for (let i = 0; i < 20; i++) {
  approveList.push({
    Id: faker.random.uuid(),
    type: '0',
    status: '启用',
    createUser: '创建人',
    createTime: (new Date()).toLocaleDateString(),
    endorses: '审批人',
    remark: '备注'
  });
}
const approveDetail = {
  type: '0',
  status: '启用',
  createUser: '创建人',
  createTime: (new Date()).toLocaleDateString(),
  endorses: '审批人',
  remark: '备注',
  endorserTypeLevel1: 0,
  endorserLevel1: '111',
  endorserTypeLevel2: 1,
  endorserLevel2: '222',
  endorserTypeLevel3: 1,
  endorserLevel3: '333',
  endorserTypeLevel4: 3,
  endorserLevel4: '444',
  endorserTypeLevel5: 2,
  endorserLevel5: '555'
};

// 物料
const materielList = [];
for (let i = 0; i < 20; i++) {
  materielList.push({
    skuId: faker.random.uuid(),
    skuName: `名称${i}`,
    skuBrand: Math.floor(Math.random() * 2),
    skuSpecification: `规格${i}`,
    skuUnit: Math.floor(Math.random() * 3),
    skuCategory: Math.floor(Math.random() * 10),
    skuGrade: Math.floor(Math.random() * 3),
    skuProperty: Math.floor(Math.random() * 4),
    bomVersion: `BOM${i}`,
    skuStatus: Math.round(Math.random()),
    storageSite: Math.floor(Math.random() * 3),
    batchNo: Math.round(Math.random() * 10000),
    quantity: Math.round(Math.random() * 10000),
    prodDate: Date.now()
  });
}

const materielDetail = {
  name: '物料SPU名称', // 物料SPU名称
  specification: '规格型号', // 规格型号
  manufacturer: '制造商', // 制造商
  bomVersion: 'BOM版本', //
  category: `${Math.floor(Math.random() * 3)}`, // 物料类别
  property: `${Math.floor(Math.random() * 3)}`, // 物料属性
  skuLevel: `${Math.floor(Math.random() * 3)}`, // 物料级别
  customCategory: `${Math.floor(Math.random() * 3)}`, // 自定义分类
  skuUnit: `${Math.floor(Math.random() * 3)}`, // 物料SKU的单位
  originalIdentity: faker.random.number(99999999), // 原厂物料编号
  originalSpecification: faker.random.number(99999999), // 原厂型号规格
  deptLevel1: `${Math.floor(Math.random() * 3)}`, // 需求一级部门
  deptLevel2: `${Math.floor(Math.random() * 3)}`, // 需求二级部门
  status: Math.round(Math.random()), // 物料SKU当前是否启用
  picture: [], // 物料SPU的图片信息
  description: '这是描述', // 简单描述
  remark: '这是备注', // 备注
  isCriticalPart: Math.round(Math.random()), // 是否安全关键件1：是 0：否
  isSparePart: Math.round(Math.random()), // 是否备件1：是 0：否
  inspectingMaterial: Math.round(Math.random()), // 是否需要来料检验1：是 0：否
  inspectingProduct: Math.round(Math.random()), // 是否需要成品检验1：是 0：否
  inspectingProcess: Math.round(Math.random()), // 是否需要过程检验1：是 0：否
  allowingProcurement: Math.round(Math.random()), // 是否允许采购1：是 0：否
  allowingOutsourcing: Math.round(Math.random()), // 是否允许委外1：是 0：否
  allowingProduction: Math.round(Math.random()), // 是否允许生产1：是 0：否
  allowingSales: Math.round(Math.random()), // 是否允许销售1：是 0：否
  createUser: `${Math.floor(Math.random() * 3)}`, //
  createTime: (new Date()).toLocaleDateString(), //
  updateUser: `${Math.floor(Math.random() * 3)}`, //
  updateTime: (new Date()).toLocaleDateString(), //
  // 库存
  inventoryStorehouseId: `${Math.floor(Math.random() * 3)}`, // 默认仓库
  inventoryUnit: `${Math.floor(Math.random() * 3)}`, // 库存单位
  inventoryUnitRate: `${Math.floor(Math.random() * 3)}`, // 库存单位转换率：转换成基本单位的转换率
  batchNumUsing: Math.round(Math.random()), // 是否启用批号管理1：是 0：否
  batchNumFlag: Math.round(Math.random()), // 批号生成规则：手动生成0/自动生成1
  seqNumUsing: Math.round(Math.random()), // 是否启用序列号管理1：是 0：否
  seqNumFlag: Math.round(Math.random()), // 序列号生成规则：手动生成0/自动生成1
  bomManagementUsing: Math.round(Math.random()), // 是否启用BOM版本管理1：是 0：否
  bomManagementFlag: Math.round(Math.random()), // BOM版本生成规则：手动生成0/自动生成1
  validitySpanUsing: Math.round(Math.random()), // 是否启用保质期管理1：是 0：否
  validitySpan: faker.random.number(999), // 保质期
  validitySpanUnit: `${Math.floor(Math.random() * 3)}`, // 保质期单位
  valertUsing: Math.round(Math.random()), // 是否启用有效期预警1：是 0：否
  valertDays: faker.random.number(99), // 提前预警天数
  qalertUsing: Math.round(Math.random()), // 是否启用数量预警1：是 0：否
  qalertStorehouseMode: Math.round(Math.random()), // 数量预警仓库模式：所有仓库0/单个仓库1
  allStorehouseMaxNum: faker.random.number(9999), // 所有仓库上限
  allStorehouseMinNum: faker.random.number(9), // 所有仓库下限
  qalerts: [{
    storehouseId: `${Math.floor(Math.random() * 3)}`, // 仓库（如果是所有仓库，则设置为0）
    maxNum: faker.random.number(99999999), // 上限
    minNum: faker.random.number(99), // 下线
  }],
  // 采购
  procurers: [`${Math.floor(Math.random() * 3)}`], // 采购员
  vendorId: `${Math.floor(Math.random() * 3)}`, // 默认供应商
  proDeptLevel1: `${Math.floor(Math.random() * 3)}`, // 采购一级部门
  proDeptLevel2: `${Math.floor(Math.random() * 3)}`, // 采购二级部门
  proUnit: `${Math.floor(Math.random() * 3)}`, // 采购单位
  proUnitRate: `${Math.floor(Math.random() * 3)}`, // 采购单位转换率：转换成基本单位的转换率
  pkgInfo: '包装信息', // 包装信息
  minOrderPro: faker.random.number(99), // 最小起订量
  maxOrderPro: faker.random.number(999), // 最大起订量
  batchInc: 20, // 批量增量
  usingSpyMgm: Math.round(Math.random()), // 启用货源控制
  // 生产
  prdUnit: `${Math.floor(Math.random() * 3)}`, // 发料单位
  prdUnitRate: faker.random.number(100), // 发料单位转换率：转换成基本单位的转换率
  prdStorehouseId: `${Math.floor(Math.random() * 3)}`, // 发料仓库
  minIssuance: faker.random.number(999), // 最小发料量
  allowingOverissuance: Math.round(Math.random()), // 允许超发1：是 0：否
  overissuanceRate: `${Math.floor(Math.random() * 3)}`, // 超发比例
  // 销售
  sellUnit: `${Math.floor(Math.random() * 3)}`, // 销售单位
  sellUnitRate: faker.random.number(100), // 销售单位转换率：转换成基本单位的转换率
  currency: `${Math.floor(Math.random() * 3)}`, // 币种
  price: faker.random.number(100), // 销售单价
  minOrder: faker.random.number(100), // 最小起订量
  maxOverissuance: faker.random.number(1000) // 最大超发量
};

const materielTypes = [
  { name: '成品', value: 'XXB' },
  { name: '半成品', value: 'XXC' },
  { name: '原材料', value: 'XXD' },
  { name: '辅料', value: 'XXE' },
  { name: '在产品', value: 'XXF' },
  { name: '工具', value: 'XXG' },
  { name: '设备', value: 'XXH' },
  { name: '消耗品', value: 'XXI' },
  { name: '费用', value: 'XXJ' },
  { name: '服务', value: 'XXK' },
  { name: '文件', value: 'XXL' },
  { name: '资产', value: 'XXM' },
  { name: '其他', value: 'XXN' }
];

// 仓库
const storeList = [];
for (let i = 0; i < 6; i++) {
  storeList.push({
    name: `仓库${i}`,
    id: faker.random.uuid(),
    type: `类型${i}`,
    address: `地址${i}`,
    keeper: `仓管员${i}`,
    mobile: '18812345678',
    status: Math.round(Math.random()),
    creator: `创建人${i}`
  });
}

const storeDetail = {
  name: '仓库的名字',
  id: '仓库的编码',
  status: '1',
  type: '仓库类型',
  creator: '创建者',
  keeper: '仓管员辛苦了',
  department: '部门',
  mobile: '18888888888',
  upperStorehouse: 'shang',
  lowerStorehouse: 'xia',
  address: '地址个啥呢',
  remark: '描述个啥呢',
  allows: [0, 1],
  posRule: '001'
};

// 供应商
const materiels = [];
for (let i = 0; i < 8; i++) {
  materiels.push({
    manufacturer: '2',
    name: '0701名称',
    sku: '2c90750064553bbc0164560725c80002',
    skuUnit: '1',
    specification: '0701规格',
  });
}
// 供应商列表
const providerList = [];
for (let i = 0; i < 20; i++) {
  providerList.push({
    bank: '031',
    bankAccountName: '033',
    bankAccountNo: '034',
    businessCertificate: '888',
    businessRegistration: '0101',
    characters: '0',
    city: '1',
    corporateRepresentative: '555',
    country: '1',
    createDeptLevel1: 'XT',
    createDeptLevel2: 'XT-KH',
    createTime: null,
    createUser: '110000',
    defaultTaxRate: '1',
    homePage: '444',
    id: faker.random.uuid(),
    industry: '2',
    invoiceType: '0',
    mailingAddress: '222',
    name: '111',
    paymentTerms: '0',
    prdAllowNo: '777',
    recordNo: '000',
    registeredAddress: '99999',
    registeredCapital: 666,
    remark: '035',
    scale: '0',
    settlement: '0',
    settlementCurrency: '0',
    status: '0',
    taxID: '032',
    vendorCreateDate: 1532275200000,
    vendorcategory: '1',
    vendorgrade: '2',
    zip: '333'
  });
}

const credits = [];
for (let i = 0; i < 3; i++) {
  credits.push({
    createTime: null,
    createUser: null,
    credential: '222',
    credentialFile: 'blob:http://localhost:8080/860b9ea3-cac8-4655-bea6-07e6a333008a',
    credentialNo: '223',
    id: '2c90750064bc08da0164bc1b956e000a',
    remark: null,
    skus: '2c907500645462eb016454b4a1220000,2c907500645462eb016454bed5df000d,2c90750064780dcf016478806f100013,2c9075006479094d01647a6c18ae0041',
    updateTime: null,
    updateUser: null,
    vaildDate: 1612800000,
    vendor: '2c90750064780dcf0164781dcadd0000',
  });
}

const contacts = [];
for (let i = 0; i < 3; i++) {
  contacts.push({
    email: '114',
    fax: '113',
    id: '2c90750064bc08da0164bc1b956d0009',
    landLine: '112',
    mobile: '15221987345',
    name: '110',
    position: '0',
    remark: '115',
    vendor: '2c90750064780dcf0164781dcadd0000'
  });
}

const providerDetail = {
  bank: '工商银行',
  bankAccountName: '上海天黎医疗器械有限公司',
  bankAccountNo: '1234567812345678',
  businessCertificate: '沪C000000',
  businessRegistration: 'ABCD000000000000',
  characters: '国有',
  city: '上海',
  corporateRepresentative: '谢敏乙',
  country: '中国',
  defaultTaxRate: '24.00%',
  homePage: 'www.tianli.com',
  industry: '医疗器械',
  invoiceType: '外购',
  mailingAddress: '上海市天黎路1号',
  name: '上海天黎医疗器械有限公司',
  paymentTerms: null,
  registeredAddress: null,
  registeredCapital: 500,
  remark: null,
  scale: '200~500人',
  settlement: '电汇',
  settlementCurrency: '人民币',
  status: '0',
  taxID: '沪税登字1234567890',
  vendorcategory: '外购',
  vendorgrade: 'A',
  zip: '201632',
  vendorContactList: contacts,
  vendorCredentialsList: credits,
  vendorSupplyList: materiels
};

// 证书设备列表
const deviceList = [];
for (let i = 0; i < 20; i++) {
  deviceList.push({
    id: faker.random.uuid(),
    name: faker.random.words(),
    deviceType: Math.floor(Math.random() * 2),
    specification: Math.floor(Math.random() * 3),
    vendor: faker.address.streetName(),
    calibrationDate: Date.now(),
    expireDate: Date.now(),
    cycle: 30,
    warnDays: '我是附件地址URL'
  });
}

// 供应商、人员证书列表
const letterList = [];
for (let i = 0; i < 8; i++) {
  letterList.push({
    id: faker.random.uuid(),
    name: faker.random.words(),
    credentialType: Math.floor(Math.random() * 2),
    descr: faker.random.words(),
    issueDate: Date.now(),
    expireDate: Date.now(),
    attachment: '附件URL',
    remark: faker.random.words()
  });
}

// 注册证证书列表
const registerList = [];
for (let i = 0; i < 20; i++) {
  registerList.push({
    registNo: faker.random.uuid(),
    productName: faker.random.words(),
    modelNo: Math.floor(Math.random() * 2),
    owner: faker.random.words(),
    desc: faker.random.words(),
    issueDate: Date.now(),
    expireDate: Date.now(),
    period: 30,
    attachment: '我是附件地址URL',
    remark: faker.random.words()
  });
}

export default {
  // 员工管理
  getStaffList: (config) => {
    console.log(config);
    return {
      status: 0,
      obj: {
        totalNum: 23,
        records: staffList
      },
      comment: '成功'
    };
  },
  getStaffDetail: () => ({
    status: 0,
    obj: staffDetail,
    comment: '成功'
  }),
  deleteStaff: () => ({ status: 0 }),
  saveStaff: () => ({
    status: 0,
    obj: {
      name: '员工一',
      employeeId: '员工ID',
      sex: '女',
      birthday: '1900-08-22',
      mobile: '16698783454',
      age: '23',
      oneLevelDept: '一级部门',
      isOneLevelMaganer: '1',
      twoLevelDept: '二级部门',
      isTwoLevelMaganer: '0',
      workingStatus: '离职',
      position: '超声事业部',
      username: 'adminuser',
      password: '111111',
      role: ['角色1', '角色2'],
      accountStatus: ''
    },
  }),
  changeStaffAccountStatus: () => ({ status: 0 }),
  // 角色管理
  getRoleList: () => ({
    status: 0,
    obj: roleList,
    comment: '成功'
  }),
  deleteRole: () => ({ status: 0 }),
  saveCustomRole: () => ({
    status: 0,
    obj: {
      id: '8888',
      roleName: '新来的'
    }
  }),
  deleteRoleEmployee: () => ({ status: 0 }),
  saveRoleEmployee: () => ({
    status: 0,
    obj: [{
      employeeId: faker.random.uuid(),
      name: '小王'
    }]
  }),
  getRoleLimits: () => ({
    status: 0,
    obj: makeRoleLimits(),
    comment: '成功'
  }),
  getDefLimitList: () => ({
    status: 0,
    obj: makeRoleLimits(),
    comment: '成功'
  }),
  saveRoleLimits: () => ({ status: 0 }),
  // 审批管理
  getApproveList: () => ({
    status: 0,
    obj: {
      totalNum: 67,
      records: approveList
    },
    comment: '成功'
  }),
  getApproveDetail: () => ({
    status: 0,
    obj: approveDetail
  }),
  deleteApprove: () => ({ status: 0 }),
  saveApprove: () => ({
    status: 0,
    obj: {
      name: '员工一',
      employeeId: '员工ID',
      sex: '女',
      birthday: '1900-08-22',
      mobile: '16698783454',
      age: '23',
      oneLevelDept: '一级部门',
      isOneLevelMaganer: '1',
      twoLevelDept: '二级部门',
      isTwoLevelMaganer: '0',
      workingStatus: '离职',
      position: '超声事业部',
      username: 'adminuser',
      password: '111111',
      roles: ['角色1', '角色2'],
      accountStatus: ''
    },
  }),
  // 物料
  getMaterielList: () => ({
    totalNum: 23,
    records: materielList
  }),
  getMaterielOutList: () => ({
    totalNum: 23,
    records: materielList
  }),
  getMaterielDetail: () => materielDetail,
  deleteMateriel: () => ({ status: 0 }),
  saveMateriel: () => ({
    status: 0,
    obj: materielList[Math.floor(Math.random() * 20)]
  }),
  getMaterielTypes: () => materielTypes,
  // 仓库
  getStoreList: () => ({
    status: 0,
    obj: {
      records: storeList,
      totalNum: 23,
      totalPageNum: 56
    },
    comment: '成功'
  }),
  getStoreDetail: () => ({
    status: 0,
    obj: storeDetail,
    comment: '成功'
  }),
  deleteStore: () => ({ status: 0 }),
  saveStore: () => ({
    status: 0,
    obj: {
      name: faker.random.uuid(),
      id: 88,
      type: Math.round(Math.random() * 100),
      address: '江西省南昌市松江大街66号',
      keeper: Math.round(Math.random()),
      mobile: Math.round(Math.random() * 100),
      remark: (new Date()).toLocaleDateString(),
      status: Math.round(Math.random()),
      creator: Math.round(Math.random() * 100)
    }
  }),
  // 供应商
  getProviderList: () => ({
    status: 0,
    obj: {
      records: providerList,
      totalNum: 23,
      totalPageNum: 56
    },
    comment: '成功'
  }),
  getProviderDetail: () => providerDetail,
  deleteProvider: () => ({ status: 0 }),
  saveProvider: () => ({
    status: 0,
    manage: {
      id: 101,
      code: faker.random.uuid(),
      name: faker.random.uuid(),
      type: Math.round(Math.random() * 100),
      rank: Math.round(Math.random()),
      property: Math.round(Math.random() * 100),
      scale: (new Date()).toLocaleDateString(),
      signFund: Math.round(Math.random()),
      signAddr: '新来的兄弟',
      status: Math.round(Math.random() * 100),
      creator: (new Date()).toLocaleDateString()
    }
  }),
  // 证书
  getCredentialWarn: () => ({
    status: 0,
    obj: {
      deviceWarnNo: 1,
      vendorWarnNo: 4,
      employeeWarnNo: 4,
      registionWarnNo: 6
    },
    comment: '成功'
  }),
  getCredentialDevices: () => ({
    status: 0,
    obj: {
      records: deviceList,
      totalNum: 23,
      totalPageNum: 56
    },
    comment: '成功'
  }),
  saveCredentialDevice: () => ({
    status: 0,
    obj: '4028ab65669b84e201669b89c2b20000',
    comment: '成功'
  }),
  deleteCredentialDevice: () => ({ status: 0 }),
  getCredentialSupplyPerson: () => ({
    status: 0,
    obj: letterList,
    comment: '成功'
  }),
  saveCredentialLetter: () => ({
    status: 0,
    obj: '4028ab65669b84e201669b89c2b20000',
    comment: '成功'
  }),
  deleteCredentialLetter: () => ({ status: 0 }),
  getCredentialRegister: () => ({
    status: 0,
    obj: {
      records: registerList,
      totalNum: 23,
      totalPageNum: 56
    },
    comment: '成功'
  }),
  saveCredentialRegister: () => ({
    status: 0,
    obj: '4028ab65669b84e201669b89c2b20000',
    comment: '成功'
  }),
  deleteCredentialRegister: () => ({ status: 0 }),
};
